package com.sp.scmdb.daoImpl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.sp.scmdb.bean.UserBean;
import com.sp.scmdb.common.dao.BaseDaoSupport;
import com.sp.scmdb.dao.DepartmentDao;
import com.sp.scmdb.entity.Department;

@Repository
public class DepartmentDaoImpl extends BaseDaoSupport<Department> implements DepartmentDao {

	/**
	 * 根据用户权限取得部门列表
	 */
	public List<Department> queryAll(UserBean user) {
		if (StringUtils.isEmpty(user.getRole().getDepartment())) {
			return this.queryHql("from Department where 1=0");
		}
		StringBuffer Hql = new StringBuffer();
		Hql.append("from Department where 1=1 ");
		if (StringUtils.isNotEmpty(user.getRole().getDepartment())) {
			Hql.append(" and id in (" + user.getRole().getDepartment() + ")");
		}
		
		return this.queryHql(Hql.toString());
	}
	
}
